﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OracleDalc
{
	class DatabaseFile : System.IO.Stream
	{
		private long _length = 0;
		private long _position = 0;
		private byte[] _body = new byte[1024];
		public override bool CanRead
		{
			get { return true; }
		}

		public override bool CanSeek
		{
			get { return true; }
		}

		public override bool CanWrite
		{
			get { return true; }
		}

		public override void Flush()
		{
			//пока без кэширования
		}

		public override long Length
		{
			get { return _body.LongLength; }
		}

		public override long Position
		{
			get { return _position; }
			set { _position = value; }
		}

		public override int Read(byte[] buffer, int offset, int count)
		{
			if (this.Position == this.Length) return 0;
			for (long i = 0; i <= count; i++)
			{
				buffer[offset + i] = _body[_position];
				_position++;
			}
			return 0;
		}

		public override long Seek(long offset, System.IO.SeekOrigin origin)
		{
			throw new NotImplementedException();
		}

		public override void SetLength(long value)
		{
			Array.Resize<byte>(ref _body, Convert.ToInt32(value));
		}

		public override void Write(byte[] buffer, int offset, int count)
		{
			if (_position + count > this.Length) this.SetLength(_position + count);
			for (long i = 0; i <= count; i++)
			{
				_body[_position] = buffer[offset + i];
				_position++;
			}
		}
	}
}
